/**
 * 
 */
package com.et114.modules.system.dictionary;

import java.util.Iterator;
import java.util.List;

import net.sf.ehcache.Cache;

import com.et114.components.ehcache.EhCacheUtils;
import com.et114.core.control.IAppInitBean;
import com.et114.core.services.impl.BaseServicesImpl;
import com.et114.modules.system.dictionary.service.IDictionaryService;
import com.et114.modules.system.dictionary.vo.BizType;

/*
 * @author guanhw
 */
public class DictionaryEhCacheManager extends BaseServicesImpl implements  IAppInitBean {
	private IDictionaryService dictionaryService ;
//	private EhCacheFactoryBean cacheFactory ;
	private Cache bizCache ; 
	public void setBizCache ( Cache bizCache ) {
		this.bizCache = bizCache;
	}

	
	public void setDictionaryService ( IDictionaryService dictionaryService ) {
		this.dictionaryService = dictionaryService;
	}
	/*
	public void setCacheFactory ( EhCacheFactoryBean cacheFactory ) {
		this.cacheFactory = cacheFactory;
	}
*/


	public synchronized void initDicBizCache(  ) throws Exception {
		/*
		boolean exist = cacheFactory.getCacheManager ( ).cacheExists ( DicConst.DIC_CACHE_BIZ_TYPE_NAME ) ;
		if ( exist )  cacheBizType.removeAll ( ) ; 
		cacheBizType = ( Cache )cacheFactory.createEhCache (  DicConst.DIC_CACHE_BIZ_TYPE_NAME ) ;
		*/
		
		List types = dictionaryService.retrieveBizTypeList ( );
		for ( Iterator iter = types.iterator ( ) ; iter.hasNext ( ) ; ) {
			BizType bizType = ( BizType ) iter.next ( );
			List options = dictionaryService.retrieveBizOptionList ( bizType.getBizTypeKey ( ) , DicConst.BIZOPTION_STATUS_ALL );
			bizType.setOptions ( options );
			EhCacheUtils.put ( bizCache , bizType ) ;
		}
	}
	
	


	public void init ( ) throws Exception {
		// TODO Auto-generated method stub
		initDicBizCache() ;
		
		
		//extends 
		/*

		*/
	}
	
	public Cache getCacheBizType ( ) {
		return bizCache;
	}
	
	/*
	public Cache getCacheBizType ( ) {
		return cacheBizType;
	}
	public void setCacheBizType ( Cache cacheBizType ) {
		this.cacheBizType = cacheBizType;
	}
*/
}
